import Vue from 'vue'
import Vuex from 'vuex'
import getters from './getters'
import camelcase from 'camelcase'
Vue.use(Vuex)
//  动态引入modules中的js，避免手动一条条引入
const context = require.context('./modules/', false, /\.js$/)
const moduleStores = {}
context.keys().forEach(key => {
  const fileName = key.slice(2, -3)
  const fileNameInCamelCase = camelcase(fileName)
  const fileModule = context(key).default
  moduleStores[fileNameInCamelCase] = {
    ...fileModule,
    namespaced: true
  }
})
const store = new Vuex.Store({
  modules: {
    ...moduleStores
  },
  getters
})

export default store
